package com.beiben.utils;

import  com.ruoyi.common.utils.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by admin on 2020/9/3.
 */
public class DateUtil extends DateUtils{

    /**
     * 计算两个时间差
     */
    public static Long getDateMinus(Date endDate, Date nowDate)
    {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        return diff;
    }

    /**
     * 计算两个时间差天数，天
     */
    public static long getDatePoorDay(Date endDate, Date startDate)
    {
        long nd = 1000 * 24 * 60 * 60;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - startDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        return day ;
    }

    /**
     * 计算前几天的时间，返回字符串
     */
    public static String getDatePoorDay(Date startDate,int pDay,String format)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        long nd = 1000 * 24 * 60 * 60;
        // 获得两个时间的毫秒时间差异
        long diff = startDate.getTime();
        // 计算差多少天
        long day = diff - (pDay * nd);
        Date date = new Date(day);
        String d = sdf.format(date);
        return d ;
    }

    /**
     * 计算前几天的时间，返回日期
     */
    public static Date getDatePoorDayReDate(Date startDate,int pDay,String format)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        long nd = 1000 * 24 * 60 * 60;
        // 获得两个时间的毫秒时间差异
        long diff = startDate.getTime();
        // 计算差多少天
        long day = diff - (pDay * nd);
        Date date = new Date(day);
        return date ;
    }

    public static final Date parseDate(final String format, final Date date)
    {
        SimpleDateFormat df = new SimpleDateFormat(format);
        String strDate = new SimpleDateFormat(format).format(date);
        try {
            return df.parse(strDate);
        } catch (ParseException e) {
            return null;
        }
    }


}
